<?php
/**
 * ============================================================================
 * Copyright (c) 2015-2018 贵州大师兄信息技术有限公司 All rights reserved.
 * siteַ: http://www.dsxcms.com
 * ============================================================================
 * @author:     David Song<songdewei@163.com>
 * @version:    v1.0.0
 * ---------------------------------------------
 * Date: 2018/11/17
 * Time: 12:17 AM
 */

namespace App\Models\Traits;


use App\Models\Cart;
use App\Models\Item;
use App\Models\ItemCollect;
use App\Models\Order;
use App\Models\Shop;
use App\Models\ShopSubscribe;

trait UserMallRelations
{
    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function shop()
    {
        return $this->hasOne(Shop::class, 'uid', 'uid')->withoutGlobalScopes();
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function shopSubscribes()
    {
        return $this->hasMany(ShopSubscribe::class, 'uid', 'uid');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasManyThrough
     */
    public function subscribedShops()
    {
        return $this->hasManyThrough(
            Shop::class,
            ShopSubscribe::class,
            'uid',
            'shop_id',
            'uid',
            'shop_id'
        );
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function items()
    {
        return $this->hasMany(Item::class, 'uid', 'uid');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function itemCollects()
    {
        return $this->hasMany(ItemCollect::class, 'uid', 'uid');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasManyThrough
     */
    public function collectedItems()
    {
        return $this->hasManyThrough(
            Item::class,
            ItemCollect::class,
            'uid',
            'itemid',
            'uid',
            'itemid'
        );
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function boughts()
    {
        return $this->hasMany(Order::class, 'buyer_uid', 'uid');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function solds()
    {
        return $this->hasMany(Order::class, 'seller_uid', 'uid');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function cartItems()
    {
        return $this->hasMany(Cart::class, 'uid', 'uid');
    }
}
